package com.madixin.chat.controller;

import com.madixin.chat.dto.ResponseResult;
import com.madixin.chat.security.LoginUserDetails;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/test")
@Tag(name = "测试接口", description = "测试相关接口")
public class TestController {

    @Operation(summary = "获取当前用户信息", description = "通过token获取当前登录用户信息")
    @SecurityRequirement(name = "BearerAuth")
    @GetMapping("/current-user")
    public ResponseResult<String> getCurrentUser() {
        LoginUserDetails loginUser = (LoginUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        
        return ResponseResult.success(loginUser.getUsername());
    }

}
